package eip.chapter7.contentrouter.mule;

import org.apache.log4j.Logger;
import org.jibx.runtime.JiBXException;
import org.mule.config.i18n.Message;
import org.mule.transformers.AbstractTransformer;
import org.mule.umo.transformer.TransformerException;

import eip.chapter7.contentrouter.util.JiBXHelper;

/**
 * We receive a String, and we transform that String to a Hotel booking.
 * 
 * @author Tijs Rademakers
 */
public class XMLToHotelBooking extends AbstractTransformer {
	
	private static final long serialVersionUID = -7018349086576029858L;
	private static final Logger logger = Logger.getLogger(XMLToHotelBooking.class);
	
	/**
	 * Do the transformation 
	 */
	@Override
	protected Object doTransform(Object xmlMessage, String encoding)
			throws TransformerException {
		String bookingString = (String) xmlMessage;		
		try {
			return JiBXHelper.createBookingFromXML(bookingString);
		} catch (JiBXException e) {
			Message msg = Message.createStaticMessage("Error transforming XML to Hotel Booking");
			throw new TransformerException(msg, e);
		}
	}
}
